package cs5226.model;

import java.sql.Timestamp;
import java.util.List;

import cs5226.util.StringUtil;

public class MemorySortRatio extends Statistics {
	private double memorySortRatio;
	
	@Override
	public String getText() {
		return StringUtil.formatDouble(memorySortRatio);
	}


	
	public MemorySortRatio(Timestamp t, double memorySortRatio) {
		super();
		super.setTs(t);
		this.memorySortRatio = memorySortRatio;
	}
	
	@Override
	public Statistics aggregate(List<Statistics> statList) {
		if (statList == null || statList.size() == 0) return null;
		
		double agrVal = 0;
		for (int i=0; i<statList.size(); i++) {
			if (statList.get(i) instanceof MemorySortRatio) {
				agrVal += ((MemorySortRatio)statList.get(i)).getMemorySortRatio(); 
			}
		}
		return new MemorySortRatio (statList.get(0).getTs(), agrVal/statList.size());
	}

	public double getMemorySortRatio() {
		return memorySortRatio;
	}

	public void setMemorySortRatio(double memorySortRatio) {
		this.memorySortRatio = memorySortRatio;
	}

}
